package net.lainiao.morethread.Chapter5.demo5;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ForkJoinTask;

/**
 * Created by Administrator on 2017/3/6.
 */
public class TaskManager {
    private List<ForkJoinTask<Integer>> tasks;

    public int getResult() {
        return result;
    }

    public void setResult(int result) {
        this.result = result;
    }

    private int result=-1;


    public TaskManager() {
        tasks = new ArrayList<>();
    }

    public void addTask(ForkJoinTask<Integer> task) {
        tasks.add(task);
    }

    public void cancelTask(ForkJoinTask<Integer> task){
        for (ForkJoinTask<Integer> item:tasks){
            if(item!=task){
                item.cancel(true);
                ((SearchNumberTask) item).writeCancelMessage();
            }
        }
    }
}
